﻿namespace TestWPF.ViewModel
{
    using System.Collections.Generic;
    using System.Text;
    using mathview.Expressions;
    using mathview.Parsers.LaTeX;
    
    public class MainVM : ViewModelBase
    {
        private string text = @"z_n^2=\frac{1+3x}{2y-\frac4x}";
        /// <summary>
        /// The text.
        /// </summary>
        public string Text
        {
            get { return text; }
            set
            {
                if (text != value)
                {
                    text = value;
                    RaisePropertyChanged("Text");
                }
            }
        }

        private ExpressionBase expression = null;
        /// <summary>
        /// The expression.
        /// </summary>
        public ExpressionBase Expression
        {
            get { return expression; }
            set
            {
                if (expression != value)
                {
                    expression = value;
                    RaisePropertyChanged("Expression");
                }
            }
        }

        public RelayCommand ParseCommand { get; private set; }

        public MainVM()
        {
            this.ParseCommand = new RelayCommand(Parse);
        }

        private void Parse()
        {
            var parser = new LaTeXStringParser();

            var expr = parser.Parse(text);

            this.Expression = expr;
        }
    }
}
